package com.lsa.helpers;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public abstract class FileUtils
{
    public static String getFileContents(String filePath) throws IOException
    {
        StringBuffer sb = new StringBuffer();
        BufferedReader br = new BufferedReader(
                new FileReader(filePath));
        
        String line = null;
        while((line = br.readLine()) != null)
        {
            sb.append(line + System.getProperty("line.separator"));
        }
        return sb.toString();
    }
    
    public static String getFileNameWithoutExtension(String fileName)
    {
        int idx = fileName.lastIndexOf('.');
        return idx > -1 ? fileName.substring(0, idx) : fileName;
    }
    
    public static String getFileName(String filePath)
    {
        int idx = filePath.lastIndexOf(File.separatorChar);
        return idx > -1 ? filePath.substring(idx+1) : filePath;
    }    
}
